home *** CD-ROM | disk | FTP | other *** search
- /*
- * convert.c
- *
- * Convert "The World Digitized" "MPS" binary format files
- * to a Micro Doc "Micro World Data Bank II" compatible format.
- * The resulting database can be used with the MAP program.
- *
- * Version 1.0 By Steve R. Sampson, Public Domain (p) February 1989
- *
- * Compiled with Turbo-C 1.5
- */
-
- #include <dir.h>
- #include <string.h>
- #include <stdio.h>
-
- /*
- * fgets.c
- *
- * Same as library fgets() only this version deletes '\n'
- */
-
- char *fgets(s, n, iop)
- char *s;
- int n;
- FILE *iop;
- {
- int c;
- char *cs;
-
- cs = s;
- while (--n > 0 && (c = getc(iop)) != EOF) {
- if (c == '\n') {
- *cs = '\0';
- break;
- } else
- *cs++ = c;
- }
-
- return((c == EOF && cs == s) ? (char *)NULL : s);
- }
-
- void convert(fpd, name, n)
- FILE *fpd;
- char *name;
- int n;
- {
- FILE *fpi;
- float lat, lon;
- int newseg, c;
-
- if ((fpi = fopen(name, "rb")) == (FILE *)NULL) {
- printf("Unable to open %s\n", name);
- return;
- }
-
- puts(name);
-
- /* Read and process the binary map "MPS" file */
-
- newseg = 1;
- while (fread(&lat, 4, 1, fpi) != 0) {
- if (fread(&lon, 4, 1, fpi) < 1) {
- printf("Database error on file %s\n", name);
- fclose(fpi);
- return;
- }
-
- if (newseg) {
- newseg = 0;
- putw(n++, fpd); /* increment segment number */
- } /* this is for future purp. */
- else
- putw(5, fpd); /* low resolution default */
-
- /*
- * Convert degrees to minutes
- */
-
- putw((int)(lat * 60.0F), fpd);
- putw((int)(lon * 60.0F), fpd);
-
- /*
- * Scan past information text
- */
-
- while ((c = fgetc(fpi)) != 0x0A) {
-
- /*
- * 0x01 value means end of segment
- */
-
- if (c == 0x01) {
- fgetc(fpi); /* get the following LF */
- newseg = 1;
- break;
- }
- }
- }
-
- fclose(fpi);
- }
-
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- char current[128], wrkcmd[80];
- FILE *fpw, *fpd;
- int i;
-
- if (argc != 2) {
- printf("Usage: convert database_name\n\n");
- printf("Where \"database_name\" is the MWDBII compatible result\n");
- exit(0);
- }
-
- /*
- * Open the work file
- */
-
- if ((fpw = fopen("convert.wrk", "r")) == (FILE *)NULL) {
- printf("Your missing \"convert.wrk\", I quit\n");
- exit(1);
- }
-
- /*
- * Open the output database file
- */
-
- if (access(argv[1], 0) == 0) {
- printf("Output file '%s' already exists.\n", argv[1]);
- exit(1);
- }
-
- if ((fpd = fopen(argv[1], "wb")) == NULL) {
- printf("Unable to create %s\n", argv[1]);
- exit(1);
- }
-
- /*
- * Get current directory and convert to lower
- * case. Capitals hurt my eyes...
- */
-
- current[0] = '\\';
- getcurdir(0, ¤t[1]);
- for (i = 1; i < strlen(current); i++)
- current[i] = tolower(current[i]);
-
- /*
- * Perform the work
- */
-
- for (;;) {
- char tmp[128];
-
- /*
- * Read work file line, and parse
- */
-
- if (fgets(wrkcmd, sizeof wrkcmd, fpw) == NULL)
- break;
-
- if ((wrkcmd[0] == '\0') || (wrkcmd[0] == '#'))
- continue;
- else if (wrkcmd[0] == '!') {
- strcpy(tmp, current);
- strcat(tmp, "\\");
- strcat(tmp, &wrkcmd[1]);
-
- if (chdir(tmp) == -1) {
- printf("Can't change dir to %s\n", tmp);
- fclose(fpw);
- fclose(fpd);
- chdir(current);
- exit(1);
- }
-
- printf("%s\n", tmp);
-
- continue;
- }
- else {
- char *n;
- int code;
-
- n = strchr(wrkcmd, ',');
- *n = '\0';
-
- code = atoi(++n);
- convert(fpd, wrkcmd, code);
- }
- }
-
- fclose(fpw);
- fclose(fpd);
- chdir(current);
-
- exit(0);
- }
-
- /* EOF */